<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FabGL: Altair8800/Altair8800.ino</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">FabGL
   </div>
   <div id="projectbrief">ESP32 VGA Controller and Graphics Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_altair8800_2_altair8800_8ino-example.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Altair8800/Altair8800.ino</div>  </div>
</div><!--header-->
<div class="contents">
<p>Altair 8800 Emulator - with ADM-31, ADM-3A, Kaypro, Hazeltine 1500 and Osborne I terminal emulation</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - www.fabgl.com</span></div><div class="line"><span class="comment">  Copyright (c) 2019 Fabrizio Di Vittorio.</span></div><div class="line"><span class="comment">  All rights reserved.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  This file is part of FabGL Library.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is free software: you can redistribute it and/or modify</span></div><div class="line"><span class="comment">  it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment">  the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><span class="comment">  (at your option) any later version.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment">  but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div><div class="line"><span class="comment">  GNU General Public License for more details.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment">  along with FabGL.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;Preferences.h&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;esp_spiffs.h&quot;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="fabgl_8h.html">fabgl.h</a>&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="fabutils_8h.html">fabutils.h</a>&quot;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;src/machine.h&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// 8&#39;&#39; disk images (338K)</span></div><div class="line"></div><div class="line"><span class="comment">// CP/M 2.2</span></div><div class="line"><span class="preprocessor">#include &quot;disks/CPM22/cpm22_dsk.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;disks/CPM22/games_dsk.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;disks/CPM22/turbopascal3_dsk.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;disks/CPM22/wordstar3_dsk.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;disks/CPM22/wordstar4_dsk.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;disks/CPM22/multiplan_dsk.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;disks/CPM22/dbaseii_dsk.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;disks/CPM22/BDSC_dsk.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;disks/CPM22/langs_dsk.h&quot;</span></div><div class="line"></div><div class="line"><span class="comment">// CP/M 1.4</span></div><div class="line"><span class="preprocessor">#include &quot;disks/CPM14/cpm141_dsk.h&quot;</span></div><div class="line"></div><div class="line"><span class="comment">// CP/M 3</span></div><div class="line"><span class="preprocessor">#include &quot;disks/CPM3/cpm3_disk1_dsk.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;disks/CPM3/cpm3_disk2_dsk.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;disks/CPM3/cpm3_build_dsk.h&quot;</span></div><div class="line"></div><div class="line"><span class="comment">// Altair DOS</span></div><div class="line"><span class="comment">//   MEMORY SIZE? [insert &quot;64&quot;]</span></div><div class="line"><span class="comment">//   INTERRUPTS? [press ENTER]</span></div><div class="line"><span class="comment">//   HIGHEST DISK NUMBER? [insert &quot;1&quot;]</span></div><div class="line"><span class="comment">//   HOW MANY DISK FILES? [insert &quot;4&quot;]</span></div><div class="line"><span class="comment">//   HOW MANY RANDOM FILES? [insert &quot;4&quot;]</span></div><div class="line"><span class="preprocessor">#include &quot;disks/AltairDOS/DOS_1_dsk.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;disks/AltairDOS/DOS_2_dsk.h&quot;</span></div><div class="line"></div><div class="line"><span class="comment">// Basic</span></div><div class="line"><span class="comment">//    MEMORY SIZE? [press ENTER]</span></div><div class="line"><span class="comment">//    LINEPRINTER? [insert &quot;C&quot;]</span></div><div class="line"><span class="comment">//    HIGHEST DISK NUMBER? [press ENTER]</span></div><div class="line"><span class="comment">//    HOW MANY FILES? [press ENTER]</span></div><div class="line"><span class="comment">//    HOW MANY RANDOM FILES? [press ENTER]</span></div><div class="line"><span class="preprocessor">#include &quot;disks/basic/basic5_dsk.h&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// Mini disk images (76K)</span></div><div class="line"></div><div class="line"><span class="comment">// CP/M 2.2</span></div><div class="line"><span class="preprocessor">#include &quot;minidisks/CPM22/cpm22_disk1_minidsk.h&quot;</span></div><div class="line"><span class="preprocessor">#include &quot;minidisks/CPM22/cpm22_disk2_minidsk.h&quot;</span></div><div class="line"></div><div class="line"><span class="comment">// Basic (need i8080 CPU)</span></div><div class="line"><span class="comment">//   MEMORY SIZE? [press ENTER]</span></div><div class="line"><span class="comment">//   LINEPRINTER? [insert &quot;C&quot;]</span></div><div class="line"><span class="comment">//   HIGHEST DISK NUMBER? [insert &quot;0&quot;]</span></div><div class="line"><span class="comment">//   HOW MANY FILES? [insert &quot;3&quot;]</span></div><div class="line"><span class="comment">//   HOW MANY RANDOM FILES? [insert &quot;2&quot;]</span></div><div class="line"><span class="preprocessor">#include &quot;minidisks/basic/basic300_5F_minidisk.h&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// Disks configuration</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// Enable this when using 8&#39;&#39; disk images (&quot;disks&quot; folder)</span></div><div class="line"><span class="preprocessor">#define DISKFORMAT Disk_338K</span></div><div class="line"></div><div class="line"><span class="comment">// Enable this when using minidisk images (&quot;minidisk&quot; folder)</span></div><div class="line"><span class="comment">//#define DISKFORMAT MiniDisk_76K</span></div><div class="line"></div><div class="line"><span class="comment">// Specify which disk image assign to drives</span></div><div class="line"><span class="preprocessor">#define DRIVE_A cpm22_dsk             // A: read only</span></div><div class="line"><span class="preprocessor">#define DRIVE_B langs_dsk             // B: read only</span></div><div class="line"><span class="preprocessor">#define DRIVE_C &quot;/spiffs/diskC.dsk&quot;   // C: read/write</span></div><div class="line"><span class="preprocessor">#define DRIVE_D &quot;/spiffs/diskD.dsk&quot;   // D: read/write</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// consts</span></div><div class="line"></div><div class="line">constexpr <span class="keywordtype">int</span> DefaultCPU = 1;       <span class="comment">// 0 = i8080, 1 = Z80</span></div><div class="line"></div><div class="line"><span class="keyword">const</span> <span class="keywordtype">char</span> *  TermStr[] = { <span class="stringliteral">&quot;ANSI/VT&quot;</span>, <span class="stringliteral">&quot;Lear Siegler ADM-3A&quot;</span>, <span class="stringliteral">&quot;Lear Siegler ADM-31&quot;</span>, <span class="stringliteral">&quot;Hazeltine 1500&quot;</span>, <span class="stringliteral">&quot;Osborne I&quot;</span>, <span class="stringliteral">&quot;Kaypro&quot;</span> };</div><div class="line">constexpr <span class="keywordtype">int</span> DefaultTermIndex = 2; <span class="comment">// Default: &quot;ADM-31&quot;</span></div><div class="line">constexpr <span class="keywordtype">int</span> MaxTermIndex = 5;     <span class="comment">// Max: &quot;Kaypro&quot;</span></div><div class="line"></div><div class="line"><span class="keyword">const</span> <span class="keywordtype">char</span> *  KbdLayStr[] = { <span class="stringliteral">&quot;US&quot;</span>, <span class="stringliteral">&quot;UK&quot;</span>, <span class="stringliteral">&quot;DE&quot;</span>, <span class="stringliteral">&quot;IT&quot;</span> };</div><div class="line"><span class="keyword">const</span> <a name="_a0"></a><a class="code" href="structfabgl_1_1_keyboard_layout.html">fabgl::KeyboardLayout</a> * KdbLay[] = { &amp;fabgl::USLayout, &amp;fabgl::UKLayout, &amp;fabgl::GermanLayout, &amp;fabgl::ItalianLayout };</div><div class="line">constexpr <span class="keywordtype">int</span> DefaultKbdLayIndex = 1; <span class="comment">// Default: &quot;UK&quot;</span></div><div class="line">constexpr <span class="keywordtype">int</span> MaxKbdLayIndex = 3;     <span class="comment">// Max: &quot;IT&quot;</span></div><div class="line"></div><div class="line"><span class="keyword">const</span> <span class="keywordtype">char</span> * ColorsStr[] = { <span class="stringliteral">&quot;Green/Black&quot;</span>, <span class="stringliteral">&quot;Yellow/Black&quot;</span>, <span class="stringliteral">&quot;White/Black&quot;</span>, <span class="stringliteral">&quot;Black/White&quot;</span>, <span class="stringliteral">&quot;Yellow/Blue&quot;</span>, <span class="stringliteral">&quot;Black/Yellow&quot;</span> };</div><div class="line"><span class="keyword">const</span> <a name="a1"></a><a class="code" href="group___enumerations.html#ga843f6f6094fb6666d0e726d7b0e06f3b">Color</a> TextColors[] = { <a name="a2"></a><a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3baf09d081210f708ef088785200c5c616e">Color::BrightGreen</a>, <a name="a3"></a><a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3baa598524eec0f8d9ba493f37390a48d12">Color::BrightYellow</a>, <a name="a4"></a><a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3babd066cc7f08ecfdd34e59e9d5348ae67">Color::BrightWhite</a>, <a name="a5"></a><a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3bab097ba4cce4536843fc9a93b5d7a5af0">Color::Black</a>,       <a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3baa598524eec0f8d9ba493f37390a48d12">Color::BrightYellow</a>, <a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3bab097ba4cce4536843fc9a93b5d7a5af0">Color::Black</a> };</div><div class="line"><span class="keyword">const</span> <a class="code" href="group___enumerations.html#ga843f6f6094fb6666d0e726d7b0e06f3b">Color</a> BackColors[] = { <a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3bab097ba4cce4536843fc9a93b5d7a5af0">Color::Black</a>,       <a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3bab097ba4cce4536843fc9a93b5d7a5af0">Color::Black</a>,        <a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3bab097ba4cce4536843fc9a93b5d7a5af0">Color::Black</a>,       <a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3babd066cc7f08ecfdd34e59e9d5348ae67">Color::BrightWhite</a>, <a name="a6"></a><a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3bab269b90a1d510bf6861b4584f7aa9720">Color::Blue</a>,         <a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3baa598524eec0f8d9ba493f37390a48d12">Color::BrightYellow</a> };</div><div class="line">constexpr <span class="keywordtype">int</span> DefaultColorsIndex = 0; <span class="comment">// Default: Green/Black</span></div><div class="line">constexpr <span class="keywordtype">int</span> MaxColorsIndex     = 5;</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// globals</span></div><div class="line"></div><div class="line">TerminalClass Terminal;</div><div class="line">Machine       altair;</div><div class="line">Mits88Disk    diskDrive(&amp;altair, DISKFORMAT);</div><div class="line">Preferences   preferences;</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> setTerminalColors()</div><div class="line">{</div><div class="line">  <span class="keywordtype">int</span> colorsIndex = preferences.getInt(<span class="stringliteral">&quot;colors&quot;</span>, DefaultColorsIndex);</div><div class="line">  Terminal.setForegroundColor(TextColors[colorsIndex]);</div><div class="line">  Terminal.setBackgroundColor(BackColors[colorsIndex]);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> setup()</div><div class="line">{</div><div class="line">  preferences.begin(<span class="stringliteral">&quot;altair8800&quot;</span>, <span class="keyword">false</span>);</div><div class="line"></div><div class="line">  Serial.begin(115200);</div><div class="line"></div><div class="line">  <span class="comment">// setup Keyboard (default configuration)</span></div><div class="line">  PS2Controller.<a name="a7"></a><a class="code" href="classfabgl_1_1_p_s2_controller_class.html#a7082e498e95fd5f5a4edfbe73923f397">begin</a>(PS2Preset::KeyboardPort0);</div><div class="line"></div><div class="line">  <span class="comment">// setup VGA (default configuration with 64 colors)</span></div><div class="line">  VGAController.<a name="a8"></a><a class="code" href="classfabgl_1_1_v_g_a_controller_class.html#acdc8b95372c01a76deeb4abe360d0295">begin</a>();</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (preferences.getBool(<span class="stringliteral">&quot;emuCRT&quot;</span>, <span class="keyword">false</span>))</div><div class="line">    VGAController.<a name="a9"></a><a class="code" href="classfabgl_1_1_v_g_a_controller_class.html#ac190a844ead4bb68817c733fb0c9a5af">setResolution</a>(<a name="a10"></a><a class="code" href="fabglconf_8h.html#a7ad04e1bb6af1e841cf9785acf037e92">VGA_640x200_70HzRetro</a>);</div><div class="line">  <span class="keywordflow">else</span></div><div class="line">    VGAController.<a class="code" href="classfabgl_1_1_v_g_a_controller_class.html#ac190a844ead4bb68817c733fb0c9a5af">setResolution</a>(<a name="a11"></a><a class="code" href="fabglconf_8h.html#ac5e5d3057b7f87058c6191c87d9a1d54">VGA_640x200_70Hz</a>);</div><div class="line"></div><div class="line">  <span class="comment">//VGAController.shrinkScreen(5, 0);</span></div><div class="line">  <span class="comment">//VGAController.moveScreen(-1, 0);</span></div><div class="line"></div><div class="line">  <span class="comment">// this speed-up display but may generate flickering</span></div><div class="line">  VGAController.<a name="a12"></a><a class="code" href="classfabgl_1_1_v_g_a_controller_class.html#a7e0814c52bfc5eecd93fbb5ebce8d423">enableBackgroundPrimitiveExecution</a>(<span class="keyword">false</span>);</div><div class="line"></div><div class="line">  Terminal.begin();</div><div class="line">  Terminal.connectLocally();      <span class="comment">// to use Terminal.read(), available(), etc..</span></div><div class="line"></div><div class="line">  Terminal.setBackgroundColor(<a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3bab097ba4cce4536843fc9a93b5d7a5af0">Color::Black</a>);</div><div class="line">  Terminal.setForegroundColor(<a class="code" href="group___enumerations.html#gga843f6f6094fb6666d0e726d7b0e06f3baf09d081210f708ef088785200c5c616e">Color::BrightGreen</a>);</div><div class="line">  Terminal.clear();</div><div class="line"></div><div class="line">  Terminal.enableCursor(<span class="keyword">true</span>);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">// shown pressing PAUSE</span></div><div class="line"><span class="keywordtype">void</span> emulator_menu()</div><div class="line">{</div><div class="line">  <span class="keywordtype">bool</span> resetRequired = <span class="keyword">false</span>;</div><div class="line">  <span class="keywordflow">for</span> (<span class="keywordtype">bool</span> loop = <span class="keyword">true</span>; loop; ) {</div><div class="line"></div><div class="line">    diskDrive.flush();</div><div class="line"></div><div class="line">    Terminal.write(<span class="stringliteral">&quot;\r\n\n\e[97m\e[40m                            ** Emulator Menu **\e[K\r\n\e[K\n&quot;</span>);</div><div class="line">    Terminal.write( <span class="stringliteral">&quot;\e[93m Z \e[37m Reset\e[K\n\r&quot;</span>);</div><div class="line">    Terminal.write( <span class="stringliteral">&quot;\e[93m S \e[37m Send Disk to Serial\e[K\n\r&quot;</span>);</div><div class="line">    Terminal.write( <span class="stringliteral">&quot;\e[93m R \e[37m Get Disk from Serial\e[K\n\r&quot;</span>);</div><div class="line">    Terminal.write( <span class="stringliteral">&quot;\e[93m F \e[37m Format SPIFFS\e[K\n\r&quot;</span>);</div><div class="line">    Terminal.printf(<span class="stringliteral">&quot;\e[93m U \e[37m CPU: \e[33m%s\e[K\n\r&quot;</span>, preferences.getInt(<span class="stringliteral">&quot;CPU&quot;</span>, DefaultCPU) == 1 ? <span class="stringliteral">&quot;Z80&quot;</span> : <span class="stringliteral">&quot;i8080&quot;</span>);</div><div class="line">    Terminal.printf(<span class="stringliteral">&quot;\e[93m P \e[37m Real CPU Speed: \e[33m%s\e[K\n\r&quot;</span>, preferences.getBool(<span class="stringliteral">&quot;realSpeed&quot;</span>, <span class="keyword">false</span>) ? <span class="stringliteral">&quot;YES&quot;</span> : <span class="stringliteral">&quot;NO&quot;</span>);</div><div class="line">    Terminal.write(<span class="stringliteral">&quot;\e[6A&quot;</span>);  <span class="comment">// cursor UP</span></div><div class="line">    Terminal.printf(<span class="stringliteral">&quot;\t\t\t\t\t\e[93m T \e[37m Terminal: \e[33m%s\e[K\n\r&quot;</span>, TermStr[preferences.getInt(<span class="stringliteral">&quot;termEmu&quot;</span>, DefaultTermIndex)] );</div><div class="line">    Terminal.printf(<span class="stringliteral">&quot;\t\t\t\t\t\e[93m K \e[37m Keyboard Layout: \e[33m%s\e[K\n\r&quot;</span>, KbdLayStr[preferences.getInt(<span class="stringliteral">&quot;kbdLay&quot;</span>, DefaultKbdLayIndex)] );</div><div class="line">    Terminal.printf(<span class="stringliteral">&quot;\t\t\t\t\t\e[93m G \e[37m CRT Mode: \e[33m%s\e[K\n\r&quot;</span>, preferences.getBool(<span class="stringliteral">&quot;emuCRT&quot;</span>, <span class="keyword">false</span>) ? <span class="stringliteral">&quot;YES&quot;</span> : <span class="stringliteral">&quot;NO&quot;</span>);</div><div class="line">    Terminal.printf(<span class="stringliteral">&quot;\t\t\t\t\t\e[93m C \e[37m Colors: \e[33m%s\e[K\n\r&quot;</span>, ColorsStr[preferences.getInt(<span class="stringliteral">&quot;colors&quot;</span>, DefaultColorsIndex)] );</div><div class="line">    Terminal.write( <span class="stringliteral">&quot;\t\t\t\t\t\e[93m O \e[37m Reset Configuration\e[K\n\r&quot;</span>);</div><div class="line"></div><div class="line">    Terminal.write(<span class="stringliteral">&quot;\n\n\e[97mPlease select an option (ENTER to exit): \e[K\e[92m&quot;</span>);</div><div class="line">    <span class="keywordtype">int</span> ch = toupper(Terminal.read());</div><div class="line">    Terminal.write(ch);</div><div class="line">    Terminal.write(<span class="stringliteral">&quot;\n\r&quot;</span>);</div><div class="line">    <span class="keywordflow">switch</span> (ch) {</div><div class="line"></div><div class="line">      <span class="comment">// 1. Send a disk image to Serial Port</span></div><div class="line">      <span class="comment">// 2. Receive a disk image from Serial Port</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;S&#39;</span>:</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;R&#39;</span>:</div><div class="line">      {</div><div class="line">        Terminal.write(<span class="stringliteral">&quot;Select a drive (A, B, C, D...): &quot;</span>);</div><div class="line">        <span class="keywordtype">char</span> drive = toupper(Terminal.read());</div><div class="line">        <span class="keywordflow">if</span> (ch == <span class="charliteral">&#39;S&#39;</span>) {</div><div class="line">          Terminal.printf(<span class="stringliteral">&quot;\n\rSending drive %c...\n\r&quot;</span>, drive);</div><div class="line">          diskDrive.sendDiskImageToStream(drive - <span class="charliteral">&#39;A&#39;</span>, &amp;Serial);</div><div class="line">        } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ch == <span class="charliteral">&#39;R&#39;</span>) {</div><div class="line">          Terminal.printf(<span class="stringliteral">&quot;\n\rReceiving drive %c...\n\r&quot;</span>, drive);</div><div class="line">          diskDrive.receiveDiskImageFromStream(drive - <span class="charliteral">&#39;A&#39;</span>, &amp;Serial);</div><div class="line">        }</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      }</div><div class="line"></div><div class="line">      <span class="comment">// Format SPIFFS</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;F&#39;</span>:</div><div class="line">        Terminal.write(<span class="stringliteral">&quot;Formatting SPIFFS removes RW disks and resets the Altair. Are you sure? (Y/N)&quot;</span>);</div><div class="line">        <span class="keywordflow">if</span> (toupper(Terminal.read()) == <span class="charliteral">&#39;Y&#39;</span>) {</div><div class="line">          Terminal.write(<span class="stringliteral">&quot;\n\rFormatting SPIFFS...&quot;</span>);</div><div class="line">          fabgl::suspendInterrupts();</div><div class="line">          esp_spiffs_format(<span class="keyword">nullptr</span>);</div><div class="line">          fabgl::resumeInterrupts();</div><div class="line">          resetRequired = <span class="keyword">true</span>;</div><div class="line">        }</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">      <span class="comment">// Reset</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;Z&#39;</span>:</div><div class="line">        Terminal.write(<span class="stringliteral">&quot;Resetting the Altair. Are you sure? (Y/N)&quot;</span>);</div><div class="line">        <span class="keywordflow">if</span> (toupper(Terminal.read()) == <span class="charliteral">&#39;Y&#39;</span>)</div><div class="line">          ESP.restart();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">      <span class="comment">// Real CPU speed</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;P&#39;</span>:</div><div class="line">        preferences.putBool(<span class="stringliteral">&quot;realSpeed&quot;</span>, !preferences.getBool(<span class="stringliteral">&quot;realSpeed&quot;</span>, <span class="keyword">false</span>));</div><div class="line">        altair.setRealSpeed(preferences.getBool(<span class="stringliteral">&quot;realSpeed&quot;</span>, <span class="keyword">false</span>));</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">      <span class="comment">// Emulate CRT</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;G&#39;</span>:</div><div class="line">        preferences.putBool(<span class="stringliteral">&quot;emuCRT&quot;</span>, !preferences.getBool(<span class="stringliteral">&quot;emuCRT&quot;</span>, <span class="keyword">false</span>));</div><div class="line">        resetRequired = <span class="keyword">true</span>;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">      <span class="comment">// CPU</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;U&#39;</span>:</div><div class="line">        preferences.putInt(<span class="stringliteral">&quot;CPU&quot;</span>, preferences.getInt(<span class="stringliteral">&quot;CPU&quot;</span>, DefaultCPU) ^ 1);</div><div class="line">        resetRequired = <span class="keyword">true</span>;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">      <span class="comment">// Terminal emulation</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;T&#39;</span>:</div><div class="line">      {</div><div class="line">        <span class="keywordtype">int</span> termIndex = preferences.getInt(<span class="stringliteral">&quot;termEmu&quot;</span>, DefaultTermIndex) + 1;</div><div class="line">        <span class="keywordflow">if</span> (termIndex &gt; MaxTermIndex)</div><div class="line">          termIndex = 0;</div><div class="line">        preferences.putInt(<span class="stringliteral">&quot;termEmu&quot;</span>, termIndex);</div><div class="line">        Terminal.setTerminalType((<a name="a13"></a><a class="code" href="group___enumerations.html#ga2d726f689f0c7c127a9327262181bbbd">TermType</a>)termIndex);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      }</div><div class="line"></div><div class="line">      <span class="comment">// Keyboard layout</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;K&#39;</span>:</div><div class="line">      {</div><div class="line">        <span class="keywordtype">int</span> kbdLayIndex = preferences.getInt(<span class="stringliteral">&quot;kbdLay&quot;</span>, DefaultKbdLayIndex) + 1;</div><div class="line">        <span class="keywordflow">if</span> (kbdLayIndex &gt; MaxKbdLayIndex)</div><div class="line">          kbdLayIndex = 0;</div><div class="line">        preferences.putInt(<span class="stringliteral">&quot;kbdLay&quot;</span>, kbdLayIndex);</div><div class="line">        Keyboard.<a name="a14"></a><a class="code" href="classfabgl_1_1_keyboard_class.html#a08b281a865847dfc514b2f0c7d77e095">setLayout</a>(KdbLay[kbdLayIndex]);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      }</div><div class="line"></div><div class="line">      <span class="comment">// Colors</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;C&#39;</span>:</div><div class="line">      {</div><div class="line">        <span class="keywordtype">int</span> colorsIndex = preferences.getInt(<span class="stringliteral">&quot;colors&quot;</span>, DefaultColorsIndex) + 1;</div><div class="line">        <span class="keywordflow">if</span> (colorsIndex &gt; MaxColorsIndex)</div><div class="line">          colorsIndex = 0;</div><div class="line">        preferences.putInt(<span class="stringliteral">&quot;colors&quot;</span>, colorsIndex);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      }</div><div class="line"></div><div class="line">      <span class="comment">// Reset configuration</span></div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;O&#39;</span>:</div><div class="line">        preferences.clear();</div><div class="line">        resetRequired = <span class="keyword">true</span>;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">      <span class="keywordflow">default</span>:</div><div class="line">        loop = <span class="keyword">false</span>;</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">    }</div><div class="line">  }</div><div class="line">  <span class="keywordflow">if</span> (resetRequired) {</div><div class="line">    Terminal.write(<span class="stringliteral">&quot;Reset required. Reset now? (Y/N)&quot;</span>);</div><div class="line">    <span class="keywordflow">if</span> (toupper(Terminal.read()) == <span class="charliteral">&#39;Y&#39;</span>) {</div><div class="line">      diskDrive.detachAll();</div><div class="line">      ESP.restart();</div><div class="line">    }</div><div class="line">  }</div><div class="line">  Terminal.localWrite(<span class="stringliteral">&quot;\n&quot;</span>);</div><div class="line">  setTerminalColors();</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> loop()</div><div class="line">{</div><div class="line">  Terminal.write(<span class="stringliteral">&quot;Formatting SPIFFS...\r&quot;</span>);</div><div class="line"></div><div class="line">  <span class="comment">// setup SPIFFS</span></div><div class="line">  esp_vfs_spiffs_conf_t conf = {</div><div class="line">      .base_path = <span class="stringliteral">&quot;/spiffs&quot;</span>,</div><div class="line">      .partition_label = NULL,</div><div class="line">      .max_files = 4,</div><div class="line">      .format_if_mount_failed = <span class="keyword">true</span></div><div class="line">  };</div><div class="line">  fabgl::suspendInterrupts();</div><div class="line">  esp_vfs_spiffs_register(&amp;conf);</div><div class="line">  fabgl::resumeInterrupts();</div><div class="line"></div><div class="line">  <span class="comment">// setup disk drives</span></div><div class="line"></div><div class="line">  diskDrive.attachReadOnlyBuffer(0, DRIVE_A);</div><div class="line">  diskDrive.attachReadOnlyBuffer(1, DRIVE_B);</div><div class="line"></div><div class="line">  Terminal.write(<span class="stringliteral">&quot;Creating Disk C...  \r&quot;</span>);</div><div class="line">  diskDrive.attachFile(2, DRIVE_C);</div><div class="line"></div><div class="line">  Terminal.write(<span class="stringliteral">&quot;Creating Disk D...  \r&quot;</span>);</div><div class="line">  diskDrive.attachFile(3, DRIVE_D);</div><div class="line"></div><div class="line">  <span class="comment">// setup SIOs (Serial I/O)</span></div><div class="line"></div><div class="line">  <span class="comment">// TTY</span></div><div class="line">  SIO SIO0(&amp;altair, 0x00);</div><div class="line">  SIO0.attachStream(&amp;Terminal);</div><div class="line"></div><div class="line">  <span class="comment">// CRT/Keyboard</span></div><div class="line">  SIO SIO1(&amp;altair, 0x10);</div><div class="line">  SIO1.attachStream(&amp;Terminal);</div><div class="line"></div><div class="line">  <span class="comment">// Serial</span></div><div class="line">  SIO SIO2(&amp;altair, 0x12);</div><div class="line">  SIO2.attachStream(&amp;Serial);</div><div class="line"></div><div class="line">  <span class="comment">// RAM</span></div><div class="line">  altair.attachRAM(65536);</div><div class="line"></div><div class="line">  <span class="comment">// boot ROM</span></div><div class="line">  altair.load(Altair88DiskBootROMAddr, Altair88DiskBootROM, <span class="keyword">sizeof</span>(Altair88DiskBootROM));</div><div class="line"></div><div class="line">  <span class="comment">// menu callback (pressing PAUSE)</span></div><div class="line">  altair.setMenuCallback(emulator_menu);</div><div class="line"></div><div class="line">  setTerminalColors();</div><div class="line">  Terminal.clear();</div><div class="line"></div><div class="line">  <span class="comment">// scrolling region (24 rows)</span></div><div class="line">  Terminal.write(<span class="stringliteral">&quot;\e[1;24r&quot;</span>);</div><div class="line"></div><div class="line">  Terminal.write(<span class="stringliteral">&quot;\e[97m\e[44m&quot;</span>);</div><div class="line">  Terminal.write(<span class="stringliteral">&quot;                    /* * * * * * * * * * * * * * * * * * * *\e[K\r\n&quot;</span>);</div><div class="line">  Terminal.write(<span class="stringliteral">&quot;\e#6&quot;</span>);</div><div class="line">  Terminal.write(<span class="stringliteral">&quot;\e#3              ALTAIR  8800\e[K\r\n&quot;</span>);</div><div class="line">  Terminal.write(<span class="stringliteral">&quot;\e#4              ALTAIR  8800\e[K\r\n&quot;</span>);</div><div class="line">  Terminal.write(<span class="stringliteral">&quot;\e#5&quot;</span>);</div><div class="line">  Terminal.write(<span class="stringliteral">&quot;\e[K\r\n&quot;</span>);</div><div class="line">  Terminal.write(<span class="stringliteral">&quot;                     \e[37mby Fabrizio Di Vittorio - www.fabgl.com\e[97m\e[K\r\n&quot;</span>);</div><div class="line">  Terminal.write(<span class="stringliteral">&quot;                     * * * * * * * * * * * * * * * * * * * */\e[K\r\n\e[K\n&quot;</span>);</div><div class="line"></div><div class="line">  Terminal.printf(<span class="stringliteral">&quot;\e[33mFree DMA Memory       :\e[32m %d bytes\e[K\r\n&quot;</span>, heap_caps_get_free_size(MALLOC_CAP_DMA));</div><div class="line">  Terminal.printf(<span class="stringliteral">&quot;\e[33mFree 32 bit Memory    :\e[32m %d bytes\e[K\r\n&quot;</span>, heap_caps_get_free_size(MALLOC_CAP_32BIT));</div><div class="line"></div><div class="line">  <span class="keywordtype">size_t</span> total = 0, used = 0;</div><div class="line">  esp_spiffs_info(NULL, &amp;total, &amp;used);</div><div class="line">  Terminal.printf(<span class="stringliteral">&quot;\e[33mSPI Flash File System :\e[32m %d bytes used, %d bytes free\e[92m\e[K\r\n\e[K\n&quot;</span>, used, total - used);</div><div class="line">  Terminal.printf(<span class="stringliteral">&quot;Press \e[93mPAUSE\e[92m to display emulator menu\e[K\r\n&quot;</span>);</div><div class="line"></div><div class="line">  setTerminalColors();</div><div class="line"></div><div class="line">  <span class="comment">// setup keyboard layout</span></div><div class="line">  <span class="keywordtype">int</span> kbdLayIndex = preferences.getInt(<span class="stringliteral">&quot;kbdLay&quot;</span>, DefaultKbdLayIndex);</div><div class="line">  Keyboard.<a class="code" href="classfabgl_1_1_keyboard_class.html#a08b281a865847dfc514b2f0c7d77e095">setLayout</a>(KdbLay[kbdLayIndex]);</div><div class="line"></div><div class="line">  <span class="comment">// setup terminal emulation</span></div><div class="line">  <span class="keywordtype">int</span> termIndex = preferences.getInt(<span class="stringliteral">&quot;termEmu&quot;</span>, DefaultTermIndex);</div><div class="line">  Terminal.setTerminalType((<a class="code" href="group___enumerations.html#ga2d726f689f0c7c127a9327262181bbbd">TermType</a>)termIndex);</div><div class="line"></div><div class="line">  <span class="comment">// CPU speed</span></div><div class="line">  altair.setRealSpeed(preferences.getBool(<span class="stringliteral">&quot;realSpeed&quot;</span>, <span class="keyword">false</span>));</div><div class="line"></div><div class="line">  CPU cpu = (preferences.getInt(<span class="stringliteral">&quot;CPU&quot;</span>, DefaultCPU) == 1 ? Z80 : i8080);</div><div class="line">  altair.run(cpu, Altair88DiskBootROMRun);</div><div class="line">}</div><div class="line"></div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
  </ul>
</div>
</body>
</html>
